package cn.woflcode.game.model;

import cn.woflcode.game.Global.Global;
import cn.woflcode.game.Global.ImageUtil;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class BigEnemyPlane {
        //---------------------状态-----------------
        //位置:x坐标
        private int x;
        //位置:y坐标
        private int y;
        //大小:宽
        private int width;
        //大小:高
        private int height;
        //飞机的图片
        private BufferedImage image = ImageUtil.getImage("enemy_boss0");
        //生命数
        private int life=2;
        //击落得分
        private  int score=2;
        //飞行速度
        private int spead=2;
        //小敌机的生命状态
        private Global.FlyObjectState state = Global.FlyObjectState.ALIVE;
        //小敌机的图片
        private BufferedImage[] images={
                ImageUtil.getImage("enemy_boss0"),
                ImageUtil.getImage("enemy_boss1"),
                ImageUtil.getImage("enemy_boss2"),
                ImageUtil.getImage("enemy_boss3"),
                ImageUtil.getImage("enemy_boss4"),
                ImageUtil.getImage("enemy_boss5"),
                ImageUtil.getImage("enemy_boss6")
        };
    //定义图片索引
    private int imageIndex=0;

    public BigEnemyPlane(){
        this.width=image.getWidth();
        this.height=image.getHeight();
        //随机取值范围 0~Global.GAME_UI_WIDTH-width
        this.x= ThreadLocalRandom.current().nextInt(0, Global.GAME_UI_WIDTH-width);

        this.y=-height;
    }
    public void drawSelf(Graphics g){
        g.drawImage(this.getImages(),x,y,null);
    }
    //移动
    public void  move(){
        this.y+=spead;
    }
    //开火
    public java.util.List<BigEnemyBullet> fire(){
        List<BigEnemyBullet> list =new ArrayList<>();
        list.add(new BigEnemyBullet(x+width/2,y+height));
        return list;
    }
    //爆炸切换图片
    public BufferedImage getImages(){
        //判断当前状态是否是存活状态
        if(state==Global.FlyObjectState.ALIVE){
            return images[0];
        }
        if (state== Global.FlyObjectState.DEATH){
            //当爆炸图片切换为最后一张图片是 DEATH->DELETABLE
            if(images.length-1==imageIndex){
                this.state= Global.FlyObjectState.DELETABLE;
            }else{
                imageIndex++;
                return images[imageIndex];
            }
        }
        return null;
    }
    //判断是否存活
    public boolean isAlive(){
        return this.life>0;
    }
    //判断是否越界
    public boolean outOfBound(){
        return this.y>Global.GAME_UI_HEIGHT;
    }

    //被攻击 生命数-1
    public void attacked(int value){
        this.life-=value;
    }
    //获取小战机外围的圆形的圆心（x,y）和半径
    //圆 x坐标
    public int getCenterX(){
        return x+width/2;
    }
    //圆y坐标
    public int getCenterY(){
        return y+height/2;
    }
    //圆半径
    public int getR(){
        return Math.min(width,height)/2;
    }
    //获取状态的getter  setter方法
    public Global.FlyObjectState getState(){
        return state;
    }
    public void setState(Global.FlyObjectState state){
        this.state=state;
    }
    //获取得分的getter  setter方法
    public int getScore(){
        return score;
    }
    public void setScore(){
        this.score=score;
    }
}
